/*
Copyright (C) 1996-1997 Id Software, Inc.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 3
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

*/

#include "fxVSIncludes.fx"

struct VS_DRAWCOMMON
{
	float4 Position : POSITION;
	float4 TexCoord : TEXCOORD;
	float4 Color : COLOUR;
	uint VertexID : SV_VERTEXID;
};

struct PS_DRAWTEXTURED
{
	float4 Position : SV_POSITION;
	float4 Color : COLOUR;
	float2 TexCoord : TEXCOORD0;
};

struct PS_DRAWCOLOURED
{
	float4 Position : SV_POSITION;
	float4 Color : COLOUR;
};


#ifdef VERTEXSHADER
static const float4 InstanceMults[4] = {
	float4 (1, 0, 1, 0),
	float4 (0, 1, 1, 0),
	float4 (1, 0, 0, 1),
	float4 (0, 1, 0, 1)
};

float2 Draw_GetInstance (float4 InstData, uint VertexID)
{
	return float2 (
		dot (InstData.xy, InstanceMults[VertexID].xy),
		dot (InstData.zw, InstanceMults[VertexID].zw)
	);
}

PS_DRAWTEXTURED DrawTexturedVS (VS_DRAWCOMMON vs_in)
{
	PS_DRAWTEXTURED vs_out;

	vs_out.Position = mul (orthoMatrix, float4 (Draw_GetInstance (vs_in.Position, vs_in.VertexID), 0, 1));
	vs_out.Color = vs_in.Color;
	vs_out.TexCoord = Draw_GetInstance (vs_in.TexCoord, vs_in.VertexID);

	return vs_out;
}

PS_DRAWCOLOURED DrawColouredVS (VS_DRAWCOMMON vs_in)
{
	PS_DRAWCOLOURED vs_out;

	vs_out.Position = mul (orthoMatrix, float4 (Draw_GetInstance (vs_in.Position, vs_in.VertexID), 0, 1));
	vs_out.Color = vs_in.Color;

	return vs_out;
}
#endif


#ifdef PIXELSHADER
Texture2D drawTexture : register(t0);

float4 DrawTexturedPS (PS_DRAWTEXTURED ps_in) : SV_TARGET0
{
	return drawTexture.Sample (drawSampler, ps_in.TexCoord) * ps_in.Color;
}

float4 DrawColouredPS (PS_DRAWCOLOURED ps_in) : SV_TARGET0
{
	return ps_in.Color;
}

/*
float4 DrawFadeScreenPS (PS_DRAWTEXTURED ps_in) : SV_TARGET0
{
	return float4 (tex2D (fadeLookup, float2 (dot (tex2D (fadeSampler, ps_in.TexCoord).rgb, float3 (0.3f, 0.59f, 0.11f)), 0.0f)).rgb, 1.0f);
}

float4 DrawGammaPS (PS_DRAWTEXTURED ps_in) : SV_TARGET0
{
	return float4 (pow (max (tex2D (drawSampler, ps_in.TexCoord).rgb, float3 (0.0f, 0.0f, 0.0f)), v_gamma), 0.0f);
}
*/
#endif
